package com.tudou.geo.service;

import java.util.Collection;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tudou.geo.dao.DigDao;
import com.tudou.geo.model.Dig;
import com.tudou.geo.service.support.BaseService;

@Service
public class DigService extends BaseService {
	@Autowired
	private DigDao digDao;
	
	public String getDigByCity(String city){
		List<Dig> list = digDao.queryDigByCity(city);
		logger.info(list.size());
		return makeStringByDigList(list);
	}
	
	private String makeStringByDigList(Collection<Dig> list){
		
		if(CollectionUtils.isEmpty(list)){
			return "[]";
		}
		
		StringBuilder sb=new StringBuilder("[");
		
		for(Dig d : list){
			sb.append(d.getItemId() + ",");
		}
		
		return sb.substring(0, sb.length()-1) + "]";
	}
}
